package com.example.gezihua.myapplication;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

/**
 * Created by gezihua on 16-12-19.
 */

public class FlySendActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fly_send_activity);
        findViewById(R.id.click).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startFlySend();
            }
        });
    }

    // 第二种方式，可以在这里画出来一个飞机并且调整位置哈

    private void startFlySend() {
        View view = findViewById(R.id.send);
        View container = findViewById(R.id.container);
        int measuredHeight = container.getMeasuredHeight();
        Log.e("suj",""+measuredHeight);
//        view.setTranslationY(0);
        int transY = measuredHeight - view.getMeasuredHeight();
        int transX = container.getMeasuredWidth() - view.getMeasuredWidth();
        ObjectAnimator translationY = ObjectAnimator.ofFloat(view,"translationY",0,-transY);
        translationY.setRepeatMode(ObjectAnimator.RESTART);
        translationY.setInterpolator(new DecelerateInterpolator());

        ObjectAnimator translationX = ObjectAnimator.ofFloat(view,"translationX",0,transX);
        translationY.setRepeatMode(ObjectAnimator.RESTART);
        translationY.setInterpolator(new LinearInterpolator());
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(500);

        animatorSet.playTogether(translationX,translationY);
        animatorSet.start();







    }
}
